package main

import (
	"fmt"
	"math/rand"
	"strings"
	"time"
)

func main() {
	//test()
	//test2()
	//test3()
	studentStore()
}

func test() {
	//var mapSection []map[string]int
	mapSection := make([]map[string]int, 5)
	for key, value := range mapSection {
		fmt.Printf("key:%v,value:%v\n", key, value)
	}
	fmt.Println()
	mapSection[0] = make(map[string]int, 2)
	mapSection[0]["a"] = 1
	mapSection[0]["b"] = 2
	mapSection[0]["c"] = 3
	mapSection[0]["d"] = 4
	//fmt.Printf("%#v\n",mapSection)
	for key, value := range mapSection {
		fmt.Printf("key:%v,value:%v\n", key, value)
	}
}

func test2() {
	rand.Seed(time.Now().UnixNano())
	var s map[string][]int
	s = make(map[string][]int, 16)
	//s["100"][0] = 44//直接使用报错

	key := "100"
	value, ok := s[key]
	if !ok {
		s[key] = make([]int, 2, 3)
		value = s[key]
	}
	value = append(value, 111)
	fmt.Println(value)
}

func test3() {
	str := "how do you do"
	ss := strings.Split(str, " ")
	fmt.Println(ss)
	valueMap := make(map[string]int)
	for _, value := range ss {
		valueMap[value]++
	}
	fmt.Println(valueMap)
}

func studentStore() {
	nums := 10
	var stuMap = make(map[int]map[string]interface{}, 16)
	for i := 1; i <= nums; i++ {
		id := i
		value, ok := stuMap[id]
		if !ok {
			value = make(map[string]interface{}, 8)
		}
		value["name"] = "lwl"
		value["age"] = rand.Intn(20)
		value["score"] = rand.Intn(100)
		stuMap[i] = value
	}
	fmt.Println(stuMap[7])
}
